package 算法.leetcode.array;

import com.alibaba.fastjson.JSON;

/**
 * @author lchenglong
 * @date 2020/10/20
 */
public class SortedSquares {

    public static void main(String[] args) {
        System.out.println(2.05*105/(105*0.84));
        // 招商 118 89 2.5
        // 正荣 105 88 2.4
        int[] A = new int[]{-4,-1,0,3,10};
        System.out.println(JSON.toJSONString(sortedSquares(A)));
    }

    public static int[] sortedSquares(int[] A) {
        if (A.length == 1) {
            return new int[]{(int) Math.pow(A[0],2)};
        }
        int[] B = new int[A.length];
        int index = A.length-1;
        for (int i=0,j = A.length-1;j>=i;) {
            int a = (int) Math.pow(A[i],2);
            int b = (int)Math.pow(A[j],2);
            if (a > b) {
                B[index--] = a;
                i++;
            } else {
                B[index--] = b;
                j--;
            }
        }
        return B;
    }
}
